<template>
  <div class="defectDegradation">
    <listTableNew v-bind="tableSetting" ref="klTable"></listTableNew>
  </div>
</template>
<script>
import {
  queryVoPageList //获取列表数据
} from "@/api/orderManagement/defectDegradation";
export default {
  name: "defectDegradation",
  data() {
    return {
      pageType: "list",
      tableSetting: {
        radioShow: false,
        showCustomBtn: true, //显示自定义列按钮
        showFilterBtn: true, //显示过滤器按钮
        pageConfig: {
          pageCode: "defectDegradation", //页面标识，用来存储过滤器以及自定义列的时候用
          userId: this.$store.getters.userInfo.id
        },
        // 查询配置
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15
          },
          // 查询条件
          searchArr: [
            {
              type: "select",
              label: "状态",
              model: "status",
              option: this.$store.getters.dirtData("question_Status")
            },
            {
              type: "input",
              label: "编号",
              model: "code"
            },
            {
              type: "input",
              label: "标题",
              model: "title"
            },
            {
              type: "input",
              label: "工单编号",
              model: "defectCode"
            },
            {
              type: "select",
              label: "降级前等级",
              model: "oldLevel",
              option: this.$store.getters.dirtData("defect_order_level")
            },
            {
              type: "select",
              label: "降级后缺陷等级",
              model: "newLevel",
              option: this.$store.getters.dirtData("defect_order_level")
            },
            // {
            //   type: "input",
            //   label: "当前节点",
            //   model: "currNodeName"
            // },
            // {
            //   type: "userOnly",
            //   label: "当前处理人",
            //   model: "currNodeUser",
            //   idsStr: "currNodeUserId"
            // },
            // {
            //   type: "userOnly",
            //   label: "创建人",
            //   model: "createByName",
            //   idsStr: "createBy",
            //   placeholder: "请输入"
            // },
            // {
            //   label: "创建时间",
            //   model: "createTime",
            //   type: "datetimerange"
            // }
          ]
        },
        // 按钮设置
        actionList: [
          {
            name: "新建",
            icon: "el-icon-plus",
            // 点击调用的方法
            method: row => {
              this.gotoDetails(row, "defectDegradationDetails", "add");
            },
            disabled:!this.$store.getters["isBtnAuth"]("add"),
            content: this.$store.getters["isBtnAuth"]("add")
              ? null
              : "未授权此功能！",
          }
        ],
        // 表格的行展示
        column: [
          {
            label: "状态",
            prop: "status",
            formatter: row => {
              let value = row.status;
              return (
                this.$store.getters["fineDirtDataName"](
                  "question_Status",
                  value
                ) || value
              );
            },
            sortable: "custom",
            width: "110px"
          },
          {
            label: "编号",
            prop: "code",
            sortable: "custom",
            width: "200px"
          },
          {
            label: "标题",
            prop: "title",
            sortable: "custom",
            showTooltip: true,
            width: "320px"
          },
          {
            label: "工单编号",
            prop: "defectCode",
            sortable: "custom",
            minWidth: "220px"
          },
          {
            label: "降级前缺陷等级",
            prop: "oldLevel",
            formatter: row => {
              let value = row.oldLevel;
              return (
                this.$store.getters["fineDirtDataName"](
                  "defect_order_level",
                  value
                ) || value
              );
            },
            sortable: "custom",
            minWidth: "150px"
          },
          {
            label: "降级后缺陷等级",
            prop: "newLevel",
            formatter: row => {
              let value = row.newLevel;
              return (
                this.$store.getters["fineDirtDataName"](
                  "defect_order_level",
                  value
                ) || value
              );
            },
            sortable: "custom",
            minWidth: "150px"
          },
          {
            label: "降级完成时间",
            prop: "finishTime",
            sortable: "custom",
            minWidth: "140px"
          },
          {
            label: "当前节点",
            prop: "currNodeName",
            sortable: "custom",
            showTooltip: true,
            minWidth: "180px"
          },
          {
            label: "当前处理人",
            prop: "currNodeUser",
            sortable: "custom",
            showTooltip: true,
            minWidth: "180px"
            
          },
          {
            label: "创建单位",
            prop: "deptName",
            sortable: "custom",
            minWidth: "210px"
          },
          {
            label: "创建人",
            prop: "createByName",
            sortable: "custom",
            minWidth: "90px"
          },
          {
            label: "创建时间",
            prop: "createTime",
            sortable: "custom",
            minWidth: "140px"
          }
        ],
        // 表格数据
        tableData: [],
        //表格方法
        tableMethods: {
          //点击行的方法
          rowClick: row => {
            this.gotoDetails(row, "defectDegradationDetails", "edit");
          }
        }
      }
    };
  },
  created() {
    /* 添加监听事件 */
    window.addEventListener("storage", this.updateData);
  },
  beforeDestroy() {
    /* 删除监听事件 */
    window.removeEventListener("storage", this.updateData);
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.$refs.klTable.getTableConfig();
      setTimeout(() => {
        this.updateData();
      }, 1000);
    },
    updateData() {
      this.$refs.klTable.searchData();
    },
    getTableData(params, sortStr) {
      let form = { ...params };
      if (sortStr) {
        form.orders = sortStr;
      }
      if (form.createTime) {
        form.createStartTime = form.createTime[0] || "";
        form.createEndTime = form.createTime[1] || "";
        delete form.createTime;
      }
      for (let i in form) {
        if (!form[i]) {
          delete form[i];
        }
      }

      // 调用接口请求数据
      queryVoPageList(form)
        .then(res => {
          let data = res.data.list || [];
          let total = res.data.total || 0;
          this.$set(this.tableSetting, "tableData", data);
          this.$set(this.tableSetting, "totalNumber", total);
        })
        .catch(e => {
          this.$set(this.tableSetting, "tableData", []);
          this.$set(this.tableSetting, "totalNumber", 0);
        });
    },
    gotoDetails(row, router, type) {
      let form = {
        pageType: type
      };
      if (type != "add") {
        form.id = row.id;
        form.status = row.status;
      }
      const { href } = this.$router.resolve({
        name: router,
        query: form
      });
      window.open(href, "_blank");
    }
  }
};
</script>
<style lang="less" scoped>
.defectDegradation {
  min-height: 500px;
  height: 100%;
}
</style>